package com.hh.test.design.proxy.staticproxy;

public class StaticProxy {

	public static void main(String[] args) {
		IUserDao userDao = new StaticProxy().new UserDao();
		ProxyDao proxy = new StaticProxy().new ProxyDao(userDao);
		proxy.save("HH");

	}

	interface IUserDao {
		boolean save(String user);
	}

	class UserDao implements IUserDao {

		public boolean save(String user) {
			System.out.println("save user:" + user);
			return true;
		}

	}

	class ProxyDao implements IUserDao {
		private IUserDao target;

		ProxyDao(IUserDao target) {
			this.target = target;
		}

		public boolean save(String user) {
			try {
				System.out.println("begin invoke proxy");
				return target.save(user);
			} finally {
				System.out.println("end invoke proxy");
			}
		}
	}
}
